package com.eqdd.yiqidian.ui.yiqiyue.fragment;

import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.YueHomeFragmentCustom;
import com.eqdd.yiqidian.adapter.MyFragmentPagerAdapter;
import com.eqdd.yiqidian.base.BaseFragment;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.TabEntity;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.ui.mine.shenqing.fragment.MyRenliFragment;
import com.flyco.tablayout.listener.CustomTabEntity;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author吕志豪 .
 * @date 17-12-9  下午1:40.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class YueHomeFragment extends BaseFragment {
    YueHomeFragmentCustom dataBinding;
    private List<Fragment> fragments;
    private SparseArray<String> urls;

    @Override
    protected void setView() {

    }

    @Override
    protected void initData() {
        fragments = new ArrayList<>();
        urls = new SparseArray();
        urls.put(0,HttpConfig.HOT_ARTICLE);
        urls.put(1,HttpConfig.GOOD_ARTICLE);
        urls.put(2,HttpConfig.QIYE_ARTICLE);
        urls.put(3,HttpConfig.HOT_ARTICLE);
        String[] titles = new String[4];
        ArrayList<String> mTitles = new ArrayList<>();
        titles[0] = "热门文章";
        titles[1] = "精品推荐";
        titles[2] = "企业文章";
        titles[3] = "易文章";
        for (int i = 0; i < titles.length; i++) {
            fragments.add(getFragment(i));
        }
        Collections.addAll(mTitles, titles);
        dataBinding.viewPager.setAdapter(new MyFragmentPagerAdapter(getChildFragmentManager(), mTitles, fragments));
        dataBinding.slidingTabStrip.setViewPager(dataBinding.viewPager, titles);
    }

    private Fragment getFragment(int i) {
        YueFragment fragment = new YueFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(Config.STATUS, i);
        bundle.putInt(Config.WHO, 0);
        bundle.putString(Config.URL, urls.get(i));
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    public ViewDataBinding initBinding(LayoutInflater inflater) {
        return dataBinding = DataBindingUtil.inflate(inflater, R.layout.fragment_yue_home, null, false);

    }

    @Override
    public void onClick(View v) {

    }
}
